import java.util.*;

/**
 * @author LKQ
 * @date 2022/5/1 13:04
 * @description HashMap + 滑动窗口 优化
 */
public class Solution2 {
    public static void main(String[] args) {

    }
    public int minimumCardPickup(int[] cards) {
        int n = cards.length;
        // 记录上一次出现该字符的位置
        Map<Integer, Integer> map = new HashMap<>();
        int ans = Integer.MAX_VALUE;
        for (int r = 0; r < n; r++) {
            if (map.containsKey(cards[r])) {
                int dis = r - map.get(cards[r]) + 1;
                ans = Math.min(ans, dis);
            }
            map.put(cards[r], r);
        }
        return  ans == Integer.MAX_VALUE ? -1 : ans;
    }
}
